package com.huike.review.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.bean.BeanUtils;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.mapper.MybatisReviewMapper;
import com.huike.review.vo.MybatisReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * mybatis复习使用的业务层
 * 注意该业务层和我们系统的业务无关，主要是让同学们快速熟悉系统的
 */
@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private MybatisReviewMapper reviewMapper;



    /**=========================================================保存数据的方法=============================================*/
    @Override
    public void saveData(Review review) {
//        review.setCreateBy("1");
//        LocalDateTime now = LocalDateTime.now();
//        //LocalDateTime转换Date
//        ZoneId zoneId = ZoneId.systemDefault();
//        ZonedDateTime zdt = now.atZone(zoneId);
//        Date createTime = Date.from(zdt.toInstant());
//        review.setCreateTime(createTime);
//        review.setUpdateBy("1");
//        review.setUpdateTime(createTime);
        reviewMapper.saveData(review);
    }

    @Override
    public void update(Review review) {
        reviewMapper.update(review);
    }

    @Override
    public void deleteById(Integer id) {
        reviewMapper.deleteData(id);
    }

    @Override
    public List<Review> getById(Integer id) {
        return  reviewMapper.getById(id);
    }

    @Override
    public Map page(Integer pageNum, Integer pageSize) {
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);
        long total = page.getTotal();
        List<Object> result = page.getResult();
        HashMap hashMap = new HashMap();
        hashMap.put("total",total);
        hashMap.put("rows",result);
        reviewMapper.Page();
        return hashMap ;
    }


}
